Page({
  data: {
    list: [],
    checkValue: [],
    handOrderNum: "",
    backgroundColor: "#739FF8",
    selectAllChecked: false,
    processName: "",
    newProcessId: "",
    currentIndex: "",
  },
  getList(handOrderNum, newProcessId, index) {
    console.log(handOrderNum);
    global.$api.post({
      url: '/api/skirt/getFinePrecessAppletInList',
      data: {
        handOrderNum: handOrderNum,
        type: index,
        // processName: this.data.processName,
        newProcessId: newProcessId,
        page: 1,
        limit: 999,
      }
    }).then(res => {
      console.log(res);
      let list = res.data.map(val => {
        return {
          ...val,
          checked: false,
        }
      })
      this.setData({
        list: list
      })
      console.log(this.list);
    })
  },
  toggleSelectAll(e) {
    console.log(e);
    if (e.detail.value.length == 0) {
      let list = this.data.list.map(val => {
        return {
          ...val,
          checked: false
        }
      })
      this.setData({
        list: list
      })
      this.setData({
        checkValue: [],
      })
    } else {
      let list = this.data.list.map(val => {
        return {
          ...val,
          checked: true
        }
      })
      let value = this.data.list.map(val => val.id);
      this.setData({
        list: list
      })
      this.setData({
        checkValue: value
      })
    }
  },
  handleClose(e) {
    global.$api.post({
      url: "api/skirt/getReleaseFinePrecess",
      data: {
        id: e.currentTarget.dataset.index
      }
    }).then(res => {
      wx.showToast({
        title: '操作成功！',
        icon: 'none'
      })
      this.getList(this.data.handOrderNum, this.data.newProcessId, this.data.currentIndex)
    })
  },
  handleSubmit() {
    console.log(this.data.checkValue);
    if (this.data.checkValue.length == 0) {
      wx.showToast({
        title: '请先选择数据！',
        icon: 'none'
      })
      return
    }
    // return
    global.$api.post({
      url: 'api/skirt/accomplishFine',
      data: {
        ids: this.data.checkValue.join(",")
      }
    }).then(res => {
      wx.showToast({
        title: '操作成功！',
        icon: 'none'
      })
      this.getList(this.data.handOrderNum, this.data.newProcessId, this.data.currentIndex)
    })
  },
  inputBlur(e) {
    console.log(e);
    this.setData({
      processName: e.detail.value
    })
    this.getList(this.data.handOrderNum, this.data.currentIndex)
  },
  checkboxChange(e) {
    console.log(e);
    if (e.detail.value.length != this.data.list.length) {
      this.setData({
        selectAllChecked: false,
      })
    } else {
      this.setData({
        selectAllChecked: true,
      })
    }
    this.setData({
      checkValue: e.detail.value
    })
  },
  onLoad: function (options) {
    console.log("options.handOrderNum", options);
    this.setData({
      handOrderNum: options.handOrderNum,
      newProcessId: options.newProcessId,
      currentIndex: options.type,
    }, function () {
      this.getList(options.handOrderNum, options.newProcessId, options.type);
    })
  }
})